package entities;

import view.ChessBoard;

import java.awt.*;
import java.util.List;
import java.util.Map;
import java.util.Set;

/***
 * Author: Mr.Zheng, Time: 2018/5/6/8：30
 * Description: 象/相
 */
public class Xiang extends BasePiece {
    public Xiang(int x, int y, Color color) {
        super(x, y, color);
        if (color == BasePiece.BLACK_PIECE) {
            this.pieceName = "象";
        } else {
            this.pieceName = "相";
        }
    }

    @Override
    public void updateAvailablePoints(Map<Point, BasePiece> pointPieceMap) {
        availablePoints.clear();
        int x = getPosition().x;
        int y = getPosition().y;

        if (y >= 5) {
            if (y > 5) {
                //首先获取象/相左上两个点坐标（一个是可移动点，一个是蹩象/相腿点）
                BasePiece piece1 = pointPieceMap.get(new Point(x - 2, y - 2));
                BasePiece piece2 = pointPieceMap.get(new Point(x - 1, y - 1));
                //当蹩象/相腿点没有棋子时
                if (piece2 == null) {
                    //当点为空或者为敌方棋子时，添加该点
                    if (piece1 == null || piece1.getColor() != this.getColor()) {
                        this.availablePoints.add(new AvailablePoint(x - 2, y - 2));
                    }
                }

                //首先获取象/相右上两个点坐标（一个是可移动点，一个是蹩象/相腿点）
                BasePiece piece3 = pointPieceMap.get(new Point(x + 2, y - 2));
                BasePiece piece4 = pointPieceMap.get(new Point(x + 1, y - 1));
                //当蹩象/相腿点没有棋子时
                if (piece4 == null) {
                    //当点为空或者为敌方棋子时，添加该点
                    if (piece3 == null || piece3.getColor() != this.getColor()) {
                        this.availablePoints.add(new AvailablePoint(x + 2, y - 2));
                    }
                }
            }

            //首先获取象/相左下两个点坐标（一个是可移动点，一个是蹩象/相腿点）
            BasePiece piece5 = pointPieceMap.get(new Point(x - 2, y + 2));
            BasePiece piece6 = pointPieceMap.get(new Point(x - 1, y + 1));
            //当蹩象/相腿点没有棋子时
            if (piece6 == null) {
                //当点为空或者为敌方棋子时，添加该点
                if (piece5 == null || piece5.getColor() != this.getColor()) {
                    this.availablePoints.add(new AvailablePoint(x - 2, y + 2));
                }
            }

            //首先获取象/相右上两个点坐标（一个是可移动点，一个是蹩象/相腿点）
            BasePiece piece7 = pointPieceMap.get(new Point(x + 2, y + 2));
            BasePiece piece8 = pointPieceMap.get(new Point(x + 1, y + 1));
            //当蹩象/相腿点没有棋子时
            if (piece8 == null) {
                //当点为空或者为敌方棋子时，添加该点
                if (piece7 == null || piece7.getColor() != this.getColor()) {
                    this.availablePoints.add(new AvailablePoint(x + 2, y + 2));
                }
            }
        }
    }
}